<?php if( !defined( 'MAIN_DIR' ) ) { header( 'Location: ' . dirname( PHP_SELF ) . '/' ); exit( ); }

	$action = ( isset( $_POST['action'] ) && $_POST['action'] ? $_POST['action'] : null );
	
	if( !isset( $_SERVER['HTTP_FLASH_UUID'] ) || $_SERVER['HTTP_FLASH_UUID'] != "oviedo-nd-zl" )	{
		echo "error=true&msg=Acceso Denegado";
		exit( );
	}

	if( $action == 'contact' )	{
		$email = ( isset( $_POST['demail'] ) && trim( $_POST['demail'] ) ? trim( $_POST['demail'] ) : NULL );
		$name = ( isset( $_POST['dname'] ) && trim( $_POST['dname'] ) ? trim( $_POST['dname'] ) : NULL );
		$comment = ( isset( $_POST['dmessage'] ) && trim( $_POST['dmessage'] ) ? trim( $_POST['dmessage'] ) : NULL );
		
		if( !$email )
			echo "&error=true&msg=E-mail not entered.";
		else if( !$name )
			echo "&error=true&msg=Name not entered.";
		else if( !$comment )
			echo "&error=true&msg=Message not entered.";
		else	{
				require_once( "classes/external/phpmailer/class.phpmailer.php" );
				
				$mailer = new PHPMailer ( );
		
				$mailer->IsHTML( true );
				$mailer->From = $email;
				$mailer->FromName = $name;
				$mailer->Subject = "Contact - www.oviedofoto.com";
				$mailer->AddReplyTo ( $email, $name );
				//$mailer->Host = "localhost";
				//$mailer->Mailer = "smtp";
		
				ob_start( );
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Contact - www.oviedofoto.com</title>
</head>
<body>
<table width="500" border="0" align="center" cellpadding="3" cellspacing="15" bgcolor="#FFFFFF" style="border:1px solid #999999">
<tr>
	<td bgcolor="#f3f3f3" align="center" style="font-family:Arial, Helvetica, sans-serif; font-size: 12px; color:#0000; font-weight:bold;">Contact - www.oviedofoto.com</td>
</tr>
<tr>
	<td align="center">
		<table width="100%" border="0" align="center" cellpadding="3" cellspacing="0" bgcolor="#F3F3F3" style="font-family:Arial, Helvetica, sans-serif; font-size: 12px; color:#0000;">
		<tr>
			<td width="40%" align="right"><b>Name:</b>&nbsp;&nbsp;</td>
			<td align="left">&nbsp;&nbsp;<?= $name ?></td>
		</tr>
		<tr bgcolor="#E3E3E3">
			<td align="right"><b>E-mail:</b>&nbsp;&nbsp;</td>
			<td align="left">&nbsp;&nbsp;<?= $email ?></td>
		</tr>
		</table>
	</td>
</tr>
<tr>
	<td bgcolor="#f3f3f3" align="center" style="font-family:Arial, Helvetica, sans-serif; font-size: 12px; color:#000000; font-weight:bold;"> Comment </td>
</tr>
<tr>
	<td align="left" class="textgral" bgcolor="#F3F3F3"style="font-family:Arial, Helvetica, sans-serif; font-size: 12px; color:#0000;"><?= $comment ?></td>
</tr>
</table>
</body>
</html>
<?

				$mailer->Body = ob_get_contents( );
				ob_clean( );
				
				$mailer->ClearAddresses( );
				$mailer->AddAddress ( 'nelson.daza@gmail.com' );
		
				if ( $mailer->Send( ) )
					echo "error=false";
				else
					echo "&error=true";
		}
	}
	else
		echo "&error=true&msg=Not allowed.";

?>